<?php
@header("content-type:text/html;charset=utf-8");

@include_once("conn.php");
@include_once("common.php");//和 mysql数据库建立连接

$account=$_POST["account"];
$pwd = $_POST["pwd"];
if(!($account&&$pwd)){
    paramsErr();
}
$sql = "select * from `userinfo` where user = '$account' or phone = '$account' or email = '$account'";

$result = mysqli_query($conn,$sql);
if(!($result)){
    $obj=array();
    $obj["status"]=false;
    $obj["detail"]="sql语句执行错误";
    $obj["sql"]=$sql;
    exit(json_encode($obj)) ;   
}
$item = mysqli_fetch_assoc($result);
$obj= array();
if($item){
    if($pwd==$item["pwd"]){
        $obj["status"]=true;
        $obj["detail"]="登录成功！";
        //后端直接存储cookie lgc标识用户身份
        setcookie("lgc",$item["user"],time()+60*60*24*7,"/");
    }else{
        $obj["status"]=false;
        $obj["detail"]="账号名或者密码输入错误!";
    }

}else{
    $obj["status"]=false;
    $obj["detail"]="该用户名未注册!";
}
echo json_encode($obj);
?>